package cn.learn.office.excel_v2;

import cn.learn.office.excel_v2.sort.HandlerColumnSort;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.List;

/**
 * 导出Excel表格需要的设置的一些数据参数；
 * 更改：增加需要手动指定生成excel表格的规则 handlerSort
 *
 * @author huangyezhan
 * @version 2.0
 * @date 2018年06月09日10:50
 */
@Deprecated
public class ExportExcelVo {
    /**
     * 确定那种方法写如Excel
     */
    private Class<? extends HandlerColumnSort> handlerSort;

    /**
     * 需要导出的Excel表格格式 .xls .xlsx
     */
    private String excelType = ".xlsx";
    /**
     * excel的表格名称
     */
    private String excelName = "新建Excel表格";
    /**
     * sheet的名字
     */
    private String sheetName = "sheet";

    //===================================以下：与表头相关的属性===================================
    /**
     * excel表格只有一行表头标题，则用 单行表头【一维数组】
     */
    private String[] singleHeader;
    /**
     * 用JSON字符串来组装多行表头，tileName、rowspan、colspan这几个参数都是固定的
     * 例子如下：
     * "["+
     * "[{tileName:'表1-1',rowspan:2,colspan:1},{tileName:'表1-2',rowspan:1,colspan:1},{tileName:'表1-3',rowspan:1,colspan:1}],"+
     * "[{tileName:'表1-1',rowspan:0,colspan:1},{tileName:'表2-1',rowspan:1,colspan:1},{tileName:'表2-2',rowspan:1,colspan:1}]"+
     * "[{tileName:'表3-1',rowspan:1,colspan:1},{tileName:'表3-2',rowspan:1,colspan:1},{tileName:'表3-3',rowspan:1,colspan:1}]"+
     * "]"
     * 注意:合并行的暂时没测试
     */
    private String   multipleHeader;
    /**
     * 表头需要的行数，单行表头默认值为1行
     * 多行表头，按照格式写，会解析读取
     */
    private int      headRowNum;
    /**
     * 需要生成的列数,跟表头个数有关
     */
    private int      columnNum;
    /**
     * 自定义列宽，如果不用自定义，就会自适应
     * 启动自定义,则把每一列的宽度都填写上
     * excel单元格的默认宽度8.11 自定义9*256=8.22，10*256=9.22，11*256=10.22
     */
    private int[]    columnWidth;
    /**
     * 表头排序,如果singleHeader/multipleHeader的排列顺序不能跟数据的顺序匹配,
     * 那就把map的key或者实体类的属性名称填好,用逗号分割，或者直接用数组填入
     * 如: "id,name,age"等,区分大小写
     */
    private String[] headSort;


    //===================================以下：跟数据内容相关的属性===================================
    /**
     * 定义指定cell内容位置的数组,只能同时指定所有列的位置
     * 指定 left,right,center
     */
    private Position[] positions;

    /**
     * 数据内容_合并行的属性名称，ArrayList4TableSort已经测试
     * 【注意：不是表头的】
     */
    private String rowspanName;
    /**
     * 数据内容_合并列的属性名称，尚未增加
     * 【注意：不是表头的】
     */
    private String colspanName;

    /**
     * 导入Excel表格的数据的集合
     */
    private List list;


    /**
     * 定义了Excel表的位置：【居左、居右、居中】的列举
     */
    public enum Position {
        /**
         * 居左1、居右2、居中3
         * 表头居中4：表头居中特殊一点
         */
        LEFT(1), RIGHT(2), CENTER(3), HEADER_CENTER(4);

        Position(int value) {
            this.value = value;
        }

        private int value;

        public int getValue() {
            return value;
        }
    }


    public Class<? extends HandlerColumnSort> getHandlerSort() {
        return handlerSort;
    }

    public void setHandlerSort(Class<? extends HandlerColumnSort> handlerSort) {
        this.handlerSort = handlerSort;
    }

    public void setExcelType(String excelType) {
        this.excelType = excelType;
    }

    public void setExcelName(String excelName) {
        this.excelName = excelName;
    }

    public void setSheetName(String sheetName) {
        this.sheetName = sheetName;
    }

    public void setSingleHeader(String[] singleHeader) {
        this.headRowNum = 1;
        this.singleHeader = singleHeader;
        this.setColumnNum(singleHeader.length);
    }

    public void setSingleHeader(String singleHeader) {
        if (singleHeader != null && !"".equals(singleHeader.trim())) {
            this.headRowNum = 1;
            this.singleHeader = singleHeader.split(",");
            this.setColumnNum(this.singleHeader.length);
        }
    }

   /* public void setMultipleHeader(String[][] multipleHeader) {
        this.multipleHeader = multipleHeader;
        this.headRowNum = multipleHeader.length;
        this.columnNum = multipleHeader[0].length;
    }*/

    public void setMultipleHeader(String multipleHeader) {
        JSONArray array = JSONObject.parseArray(multipleHeader);
        JSONArray o     = (JSONArray) array.get(0);
        this.headRowNum = array.size();
        this.columnNum = o.size();
        this.multipleHeader = multipleHeader;
    }

    public void setHeadRowNum(int headRowNum) {
        this.headRowNum = headRowNum;
    }

    public void setColumnNum(int columnNum) {
        this.columnNum = columnNum;
    }

    public void setColumnWidth(int[] columnWidth) {
        this.columnWidth = columnWidth;
    }

    public void setHeadSort(String[] headSort) {
        this.headSort = headSort;
    }

    public void setHeadSort(String headSort) {
        if (headSort != null && !"".equals(headSort.trim())) {
            this.headSort = headSort.split(",");
        }
    }

    public void setRowspanName(String rowspanName) {
        this.rowspanName = rowspanName;
    }

    public void setColspanName(String colspanName) {
        this.colspanName = colspanName;
    }

    public void setList(List list) {
        this.list = list;
    }

    public void setPositions(Position[] positions) {
        this.positions = positions;
    }


    public String getExcelType() {
        return excelType;
    }

    public String getExcelName() {
        return excelName;
    }

    public String getSheetName() {
        return sheetName;
    }

    public String[] getSingleHeader() {
        return singleHeader;
    }

    public String getMultipleHeader() {
        return multipleHeader;
    }

    public int getColumnNum() {
        return columnNum;
    }

    public int getHeadRowNum() {
        return headRowNum;
    }

    public String[] getHeadSort() {
        return headSort;
    }

    public int[] getColumnWidth() {
        return columnWidth;
    }

    public List getList() {
        return list;
    }

    public String getRowspanName() {
        return rowspanName;
    }

    public String getColspanName() {
        return colspanName;
    }

    public Position[] getPositions() {
        return positions;
    }

}
